package com.xinzhi.savingpot.userinfo.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.xinzhi.savingpot.userinfo.mapper.IAuthentication;
import com.xinzhi.savingpot.userinfo.service.IAuthenticationService;
import com.xinzhi.savingpot.util.BaseResponse;
import com.xinzhi.savingpot.util.Tools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AuthenticationImpl implements IAuthenticationService {
    @Autowired
    private IAuthentication iAuthentication;

    @Override
    public String addCertification(String realName, String nationalldentifiCation, String userId) {
        int user = Integer.valueOf(userId);
        int examination = iAuthentication.examination(user);
        if(examination==0){
            if(realName!=null){
                if(nationalldentifiCation!=null){
                    int repeat = iAuthentication.repeat(realName, nationalldentifiCation);
                    if(repeat==0){
                        String s = Tools.IdCardCheck(realName, nationalldentifiCation);
                        int i = iAuthentication.addCertification(realName, nationalldentifiCation, user);
                        return JSONObject.toJSONString(new BaseResponse(200,"认证成功",s));
                    }

                }else{
                    return JSONObject.toJSONString(new BaseResponse(400,"请输入身份证号码"));
                }
            }else {
                return JSONObject.toJSONString(new BaseResponse(400,"请输入姓名"));
            }
        }else{
            return JSONObject.toJSONString(new BaseResponse(400,"此身份已经初级实名认证"));
        }



        return JSONObject.toJSONString(new BaseResponse(200,"成功",userId));
    }
}
